<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use \kucha\ueditor\UEditor;


use yii\helpers\ArrayHelper;
use yii\helpers\Url;


/* @var $this yii\web\View */
/* @var $model backend\models\Document */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="document-form">
    <div id="main-content">
        <div id="top-alert" class="fixed alert alert-error" style="display: none;">
            <button class="close fixed" style="margin-top: 4px;">
                ×
            </button>
            <div class="alert-content">
                这是内容
            </div>
        </div>
        <div id="main" class="main" style="min-height: 20px;">
            <!-- nav -->
            <!-- nav -->
     
       
            <!-- 标签页导航 -->
            <div class="tab-wrap">
                <ul class="tab-nav nav">
                    <li data-tab="tab1" class="current">
                        <a href="javascript:void(0);">
                            基础
                        </a>
                    </li>
                    <li data-tab="tab2" class="">
                        <a href="javascript:void(0);">
                            扩展
                        </a>
                    </li>
                </ul>
                
                
                
                <div class="tab-content" style="display: block;">
                    <!-- 表单 -->
                      <?php $form = ActiveForm::begin(); ?>
                    
                        <!-- 基础文档模型 -->
                        <div id="tab1" class="tab-pane tab1 in">
                            <div class="form-item cf">
                               
                                <div class="controls">

                                    <?= $form->field($model, 'category_id')->dropDownList(empty($categoryTree)?array(array()):ArrayHelper::map(array_merge([['id'=>'0','title'=>'项级父类']],$categoryTree), "id", "title"))->label('内容分类'.'<span class="check-tips">
                                        （选择内容所归属 的分类）
                                    </span>') ?>
                                    <!--<input type="text" class="text input-large" name="title" value="">-->
                                </div>
                            </div>
                             
                            <div class="form-item cf">
                               
                                <div class="controls">
                                     <?= $form->field($model, 'title')->textInput(['maxlength' => true])->label('文章标题'.'<span class="check-tips">
                                        （文档标题）
                                    </span>') ?>
                                    <!--<input type="text" class="text input-large" name="title" value="">-->
                                </div>
                            </div>
                            <div class="form-item cf">
                                <label class="item-label">
                                    文章内容
                                    <span class="check-tips">
                                    </span>
                                </label>
                                <div class="controls">
                                    <label class="textarea">
                                    <?=$form->field($modelArticle,'content')->widget('kucha\ueditor\UEditor',[
                                            'clientOptions' => [
                                                //编辑区域大小
                                                'initialFrameWidth' => '960',
                                                'initialFrameHeight' => '450',
                                                //设置语言
                                                //'lang' =>'en', //中文为 zh-cn
                                                //定制菜单
                                        ]]);?>
                                    </label>
                                </div>
                            </div>
                            <div class="form-item cf">
                       
                                <div class="controls">
                                    <?= $form->field($model, 'name')->textInput(['maxlength' => false,'style'=>'width:200px;'])->label('标识'.'<span class="check-tips">
                                        同一根节点下标识不重复
                                    </span>') ?>
                                </div>
                            </div>
                            <div class="form-item cf">
               
                                <div class="controls">
                                    <label class="textarea input-large">                                        
                                         <?= $form->field($model, 'description')->textarea(['row' =>5,'style'=>'width:375px;'])->label('描述'.'<span class="check-tips">
                                        请填写内容的简短描述 
                                    </span>') ?>
                                    </label>
                                </div>
                            </div>
                            <div class="form-item cf">
     
                                <div class="controls">
                                     <?= $form->field($modelArticle, 'keywords')->textInput(['maxlength' => false,])->label('关键词'.'<span class="check-tips">
                                        填写关键词/seo 用 "," 号隔开  "," 为半角字符
                                    </span>') ?>
                                </div>
                            </div>
                        </div>
                        
                        
                        
                        <!--tab2 start-->
                        <div id="tab2" class="tab-pane  tab2" style="display: none;">
                            <div class="form-item cf">
  
                                <div class="controls">
                               
        <?=$form->field($model, 'type')->dropDownList(ArrayHelper::map(
                
                array(
                    
                    array(
                        'id' =>1,
                        'title'=>'目录'
                    ),
                    
                    array(
                        'id' =>2,
                        'title'=>'主题'
                    ),
                    
                    array(
                        'id' =>3,
                        'title'=>'段落'
                    ),
                    
                )
                
                , "id", "title"),['style'=>'width:200px;'])->label('内容类型');?>
    
                                </div>
                            </div>
                            <div class="form-item cf">
                                <label class="item-label">
                                    可见性
                                    <span class="check-tips">
                                    </span>
                                </label>
                                <div class="controls">
                                  <?=$form->field($model, 'type')->dropDownList(ArrayHelper::map(
                
                array(
                    
                    array(
                        'id' =>1,
                        'title'=>'可见'
                    ),
                    
                    array(
                        'id' =>0,
                        'title'=>'不可见'
                    ),
   
                    
                )
                , "id", "title"),['style'=>'width:200px;'])->label('内容类型');?>
                                </div>
                            </div>
                            <div class="form-item cf">
                               
                                    <?= $form->field($model, 'level')->textInput(['maxlength' => false,'value'=>'0','style'=>'width:60px;'])->label('优先级'.'<span class="check-tips">
                                        （越高排序越靠前）
                                    </span>') ?>
                            </div>
<!--                            <div class="form-item cf">
                                <label class="item-label">
                                    推荐位
                                    <span class="check-tips">
                                        （多个推荐则将其推荐值相加）
                                    </span>
                                </label>
                                <div class="controls">
                                    <label class="checkbox">
                                        <input type="checkbox" value="1" name="position[]">
                                        列表推荐
                                    </label>
                                    <label class="checkbox">
                                        <input type="checkbox" value="2" name="position[]">
                                        频道推荐
                                    </label>
                                    <label class="checkbox">
                                        <input type="checkbox" value="4" name="position[]">
                                        首页推荐
                                    </label>
                                </div>
                            </div>-->
                            <div class="form-item cf">
                                <label class="item-label">
                                    封面
                                    <span class="check-tips">
                                        （0-无封面，大于0-封面图片ID，需要函数处理）
                                    </span>
                                </label>
                                <div class="controls">
                                    <div class="controls">
                                        <div id="upload_picture_cover_id" class="uploadify" style="height: 30px; width: 120px;">
                                            <div id="upload_picture_cover_id-button" class="uploadify-button " style="height: 30px; line-height: 30px; width: 120px;clear:both;">
                                                <span class="uploadify-button-text" style="position: relative;">
                                                    
                                                 <input type="file" id="uploadify" name="file"><!-- 上传按钮 -->  
                                                 <div id="alertDiv"></div>
                                                 
                                                
                        <?=""//$form->field($modelArticle, 'image')->fileInput(['onclick'=>'uploadimage(this,"'.Url::toRoute("/document/uploadimage").'")']) ?>
                                                </span>
                                            </div>
                                        </div>
                                        <img src="" style="display:none;width:100px;height:100px;left:100px;clear: both;" id="imgBox"/>
                                        <div class="upload-img-box" style="margin-top:50px;">
                                            
                                            <input type="hidden" id="imagedata" name="DocumentArticle[image]" value="" />
                                        </div>
                                    </div>
                                </div>
                            </div>
                            
                            
                            <div class="form-item cf">
                 
                                <div class="controls">
                                   <?= $form->field($model, 'view')->textInput(['maxlength' => true,'value'=>'0','style'=>'width:60px;'])->label(' 浏览量'.'<span class="check-tips">
                                        （测试起始浏览量）
                                    </span>') ?>
                                </div>
                            </div>
                
            
                            <div class="form-item cf">
                                <label class="item-label">
                                    创建时间
                                    <span class="check-tips">
                                    </span>
                                </label>
                                <div class="controls">
                                    <input type="text" id="datetimepicker" name="Document[create_time]" class="text time" value="<?=date("m/d/Y")?>" placeholder="请选择时间">
                                </div>
                            </div>
         
                            <div class="form-item cf">
                        
                                <div class="controls">
                                         <?= $form->field($model, 'link_id')->textInput(['maxlength' => true,'value'=>'0','style'=>'width:200px;'])->label(' 外链'.'<span class="check-tips">
                                        （（0-非外链，大于0-外链ID,需要函数进行链接与编号的转换））
                                    </span>') ?>
                                </div>
                            </div>
                            <div class="form-item cf">
                           
                                <div class="controls">
                                         <?= $form->field($modelArticle, 'template')->textInput(['maxlength' => true])->label(' 详情页显示模板'.'<span class="check-tips">
                                        （参照render方法参数的定义）
                                    </span>') ?>
                                </div>
                            </div>
                        </div>
                        
                        
                        
                        
                        <div class="form-item cf">
                            <button class="btn submit-btn ajax-post" id="submit" type="submit"
                            target-form="form-horizontal">
                                确 定
                            </button>
                            <a class="btn btn-return" href="javascript:widnow.location.go(-1)">
                                返 回
                            </a>
                                
                            <input type="hidden" name="Document[uid]" value="<?=  Yii::$app->user->id;?>">
                            <?php
                                if(Yii::$app->controller->action->id == "update"){
                                   
                                    echo "<input type='hidden' name='Document[id]' value='".$model->id."'>";
                                    echo "<input type='hidden' name='DocumentArticle[id]' value='".$model->id."'>";
                                    
                                }
                            ?>
                            
                            <input type="hidden" name="Document[model_id]" value="2">
                            <input type="hidden" name="Document[status]" value="1">
                             
                            <input name="_csrf-backend" type="hidden" id="_csrf-backend" value="<?= Yii::$app->request->csrfToken ?>">
                        </div>
                  <?php ActiveForm::end(); ?>
                        
                </div>
            </div>
        </div>
    </div>
</div>



<?php

//tab 切换JS 
//$this->registerJsFile(Yii::$app->homeUrl.'/css/ajaxfileupload.js');
$uploadPath = Url::toRoute("/document/uploadimage");
$_crsf = Yii::$app->request->getCsrfToken();
$js =<<<JS
     $(".tab-nav li").click(function(){
       
       $(this).attr("class","current").siblings().attr("class",'');
       
       var tabname = $(this).attr("data-tab");
       $("#"+tabname).css({"display":"block"}).siblings(".tab-pane").css({"display":"none"});
   }) 
      
                  
JS;
    $this->registerJs($js);

?>


<?php  
$csrfParam = Yii::$app->request->csrfParam;  
$csrfToken = Yii::$app->request->csrfToken;  
$uploadUrl = Yii::$app->urlManager->createUrl('/document/uploadimage');
$assetPath = Yii::$app->basePath;
$fileName = substr(md5(time()), 0,18);
$this->registerJs("  
$(function(){ 
    var maxFileSize = 10 * 1024 * 1024;  
    $('#uploadify').uploadify({    
        'debug'     : false, //开启调试    
        'auto'      :true,  //是否自动上传    
        'buttonText':'选择照片',  //按钮上的文字  
        'swf'       : 'assets/uploadify-v3.1/uploadify.swf',//flash      
        'queueID'   :'uploadfileQueue',  //文件选择后的容器ID    
        'uploader'  :'$uploadUrl',  //后台action  
        'width'     :'75',  //按钮宽度  
        'height'    :'24',  //按钮高度  
        'multi'     :true,  //是否支持多文件上传，默认就是true  
        'fileObjName':'file',//后台接收的参数，如：使用struts2上传时，后台有get,set方法的接收参数  
        'fileTypeDesc':'支持的格式：',//  可选择文件类型说明  
        'fileTypeExts':'*.jpg;*.jpge;*.gif;*.png',  //允许上传文件的类型  
        'fileSizeLimit': maxFileSize,  //文件上传的最大大小  
        
        'formData': { '$csrfParam': '$csrfToken','fname':'$fileName' },
        'removeTimeout':1,    
        //返回一个错误，选择文件的时候触发    
        'onSelectError':function(file, errorCode, errorMsg){    
            switch(errorCode) {    
                case -100:    
                    alert('上传的文件数量已经超出系统限制的'+$('#file_upload').uploadify('settings','queueSizeLimit')+'个文件！');    
                    break;    
                case -110:    
                    alert('文件 ['+file.name+'] 大小超出系统限制的'+$('#file_upload').uploadify('settings','fileSizeLimit')+'大小！');    
                    break;    
                case -120:    
                    alert('文件 ['+file.name+'] 大小异常！');    
                    break;    
                case -130:    
                    alert('文件 ['+file.name+'] 类型不正确');    
                    break;    
            }    
        },    
        //检测FLASH失败调用    
        'onFallback':function(){    
            alert('您未安装FLASH控件，无法上传图片！请安装FLASH控件后再试。');    
        },    
        'onSelect': function(file){  
            $('#alertDiv').text('正在上传...');  
            $('#alertDiv').show();  
        },  
        //上传到服务器，服务器返回相应信息到data里    
        'onUploadSuccess':function(file, data, response){    
            var json = eval('(' + data + ')'); 
            //如需上传后生成预览，可在此操作  
            
            $('#imagedata').val(json.url);
            $('#imgBox').attr('src',json.url);
            
            $('#imgBox').show();
           

        },  
        'onQueueComplete': function(queueData){ //队列里所有的文件处理完成后调用  
            //alert(queueData.uploadsSuccessful);  
            $('#alertDiv').hide();  
        },
//         'onUploadStart': function (file) { 
//              $('#file_upload').uploadify('settings', 'formData', { '$csrfParam': '$csrfToken' });  
//             //在onUploadStart事件中，也就是上传之前，把参数写好传递到后台。  
//        }
    });    
});    
    
$(function(){

 $('#datetimepicker').click(function(){
 
   $(this).datepicker();

})
 

})

");  
?> 